home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: 76623,2065@compuserve.com (Bobby Martin)
- Newsgroups: comp.lang.c++
- Subject: Re: HELP: Algorithm for ordering (x,y) coordinates
- Date: 18 Mar 1996 17:03:41 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4ik51d$euq@dub-news-svc-4.compuserve.com>
- References: <314B0266.456A@mit.edu>
- Reply-To: 76623,2065@compuserve.com (Bobby Martin)
- NNTP-Posting-Host: ad51-239.compuserve.com
- X-Newsreader: IBM NewsReader/2 v1.03
-
- In <314B0266.456A@mit.edu>, Imran Haq <ihaq@mit.edu> writes:
- >Here is a problem that I can't seem to express in code easily using STL:
- ..
- <snip>
- ..
- >requires only two arguments, not the 3 I need to compute order. In fact, what
- >I really need is to have this custom function automatically accept the
- >first coordinate pair as a reference point, and modify the order of the 2nd and 3rd
- >points if they are not anticlockwise.
- >
- >Any suggestions? Or do I need to write a sort algorithm outside what STL provides?
- >
- >
- >Imran Haq
- >ihaq@mit.edu
-
- Try writing a compare function for the points that accepts the two points
- to be swapped. Then set up two distinct point variables from your set to
- be used as pivot points in your compare function. Inside the compare
- function, find one of the two pivots that is not equal to either of the points
- passed into the compare function, and use is as the third point to find the
- vectors for your cross product.
-
- PS: I advise using a class with two static member variables as your repository
- for the two pivot points, like so:
-
- class PointHolder {
- private:
- Point a;
- Point b;
- public:
- Point& a() {return a;}
- Point& b() {return b;}
- void a(const Point& newA) {a=newA;}
- void b(const Point& newB) {b=newB;}
- };
-
- Hope that helps!
-
- Bobby Martin
-
- Feel free to email me if anything is unclear.
-